﻿using AutoMapper;
using MediatR;
using Process.API.Application.Command.Action.ProductionOrders;
using Process.Domain;
using Process.ErrorCode;
using Process.Infrastructure.Implement;

namespace Process.API.Application.Handler.Action.ProductionOrdersAction
{
    public class UpdProductionOrdersHandler:IRequestHandler<UpdProductionOrdersCommand,APIResult<int>>
    {
        DatabaseContext db;
        IMapper mapper;

        public UpdProductionOrdersHandler(DatabaseContext db, IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }

        public async Task<APIResult<int>> Handle(UpdProductionOrdersCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var repmodel = mapper.Map<ProductionOrders>(request);
            var m = await db.SqlSugar.Updateable(repmodel).ExecuteCommandAsync();
            result.Code = APIEnum.Ok;
            result.Message = "生产工单修改成功";
            result.Data = m;
            return await Task.FromResult(result);
        }
    }
}
